﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FotoAnotSharp
{
    /// <summary>
    /// This class represent hierarchy of graphical objects.
    /// Contains parent of this hierarchy and collection of objects
    /// </summary>
    public class GraphicalObjectHiearchy
    {
        public GraphicalObjectHiearchy()
        { }

        public GraphicalObject Parent
        { get; set; }

        private Dictionary<string, GraphicalObject> mObjects = new Dictionary<string, GraphicalObject>();
        public void AddObjectAllias(GraphicalObject obj, string allias)
        {
            mObjects[allias] = obj;
            obj.AddAllias(allias);
        }

        public bool TryGetObject(string name, out GraphicalObject obj)
        {
            return mObjects.TryGetValue(name, out obj);
        }

        public GraphicalObject CreatObject(string name)
        {
            if (mObjects.ContainsKey(name))
                throw new InvalidOperationException("Object with name already created");

            return (mObjects[name] = new GraphicalObject(this, name));
        }
    }
}
